import type { DictItem } from './typing';

export const dictList: {
  occupation: DictItem[];
  marital: DictItem[];
  sex: DictItem[];
} = {
  occupation: [
    {
      code: 1,
      text: '学生',
    },
    {
      code: 2,
      text: '老师',
    },
    {
      code: 3,
      text: '程序员',
    },
    {
      code: 4,
      text: '工程师',
    },
  ],
  marital: [
    {
      code: 1,
      text: '未婚',
    },
    {
      code: 2,
      text: '已婚',
    },
    {
      code: 3,
      text: '离异',
    },
    {
      code: 4,
      text: '丧偶',
    },
    {
      code: 5,
      text: '保密',
    },
  ],
  sex: [
    {
      code: 0,
      text: '女',
    },
    {
      code: 1,
      text: '男',
    },
  ],
};

/**
 * 根据字段类型获取字段列表
 * @param key
 */
export function getDictByKey(key: 'occupation' | 'marital' | 'sex') {
  return dictList[key];
}

/**
 * 根据字段类型&code获取text
 * @param dictKey
 * @param code
 */
export function getDictTextByCode(
  dictKey: 'occupation' | 'marital' | 'sex',
  code: number
) {
  return dictList[dictKey]?.find((item) => item.code === code)?.text;
}
